const mysql = require("mysql2/promise");
const { hashPassword } = require("./utils/hash");

async function addTestUsers() {
  const connection = await mysql.createConnection({
    host: "localhost",
    user: "root",
    password: "123456",
    database: "mall_db",
  });

  const users = [
    {
      username: "admin",
      password: "123456",
      email: "admin@example.com",
      role: "admin",
    },
    {
      username: "user1",
      password: "123456",
      email: "user1@example.com",
      role: "user",
    },
    {
      username: "user2",
      password: "123456",
      email: "user2@example.com",
      role: "user",
    },
  ];

  for (const u of users) {
    const { salt, hash } = hashPassword(u.password);
    await connection.execute(
      "INSERT INTO users (username, password, salt, email, role) VALUES (?, ?, ?, ?, ?)",
      [u.username, hash, salt, u.email, u.role]
    );
  }

  console.log("测试用户已插入");
  await connection.end();
}

addTestUsers();
